<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-07-16 11:24:24
 * @LastEditTime: 2023-05-17 22:03:31
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 代码生成
 * @FilePath: \vue3-element-plus-web\src\views\SysManage\Robot\index.vue
 * Copyright 版权声明
-->
<template>
  <div class="app-container">
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-width="100px"
      style='max-width: 400px;'
    >
      <el-form-item label="包名：" prop="packageName">
        <el-input v-model="temp.packageName" placeholder="请输入包名"></el-input>
      </el-form-item>

      <el-form-item label="类名：" prop="className">
        <el-input v-model="temp.className" placeholder="请输入类名"></el-input>
      </el-form-item>

      <el-form-item label="表名：" prop="className">
        <el-input v-model="temp.tableName" placeholder="请输入表名"></el-input>
      </el-form-item>

      <el-form-item label="是否分离：" prop="isSeparate">
        <el-radio-group v-model="temp.isSeparate">
          <el-radio
            v-for="item in SERVE_ENUM"
            :key="item.value"
            :label="item.value">
            {{item.label}}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="">
        <el-button type="primary" @click="handleGenerate">
          <el-icon><TakeawayBox /></el-icon>
          生成代码
        </el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
// 图标组件
import { TakeawayBox } from '@element-plus/icons-vue'
import { mapGetters } from 'vuex'
import { SERVE_ENUM } from '@/config/views/SysManage/Robot'
import { genderCode } from '@/api/SysManage/robot'
import { resolveBlob } from '@/utils/fs'

export default {
  name: 'SysRobot',
  computed: {
    ...mapGetters([
      'drawerVisible'
    ])
  },
  components: {
    TakeawayBox
  },
  data() {
    return {
      temp: {
        packageName: 'com.jingxin.zero',
        className: '',
        tableName: '',
        isSeparate: 1
      },
      rules: {
        packageName: [
          { required: true, message: '请输入包名', trigger: 'change' },
          { max: 50, message: '包名最大长度50位', trigger: 'change' }
        ],
        className: [
          { required: true, message: '请输入类名', trigger: 'change' },
          { max: 50, message: '类名最大长度50位', trigger: 'change' }
        ],
        tableName: [
          { required: true, message: '请输入表名', trigger: 'change' },
          { max: 50, message: '表名最大长度50位', trigger: 'change' }
        ],
        isSeparate: [
          { required: true, message: '请选择是否分离', trigger: 'change' }
        ]
      },
      // 是否分离 枚举
      SERVE_ENUM
    }
  },
  watch: {
  },
  created() {
  },
  activated() {
  },
  deactivated() {
  },
  methods: {
    // 生成
    handleGenerate() {
      // genderCode()
      this.$refs['dataForm'].validate().then(valid => {
        // 获取要提交的数据
        const data = this.temp
        genderCode(data).then(response => {
          resolveBlob(response)
          this.$notify({
            title: '成功',
            message: '生成成功',
            type: 'success',
            duration: 2000
          })
        }).catch(err => {
          err
        })
      }).catch(err => {
        err
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.app-container{
  background-color: #fff;
  padding: 20px;
}
</style>
